package com.learn.databinding.layoutandbindingexpression

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import com.exercise.struct.base.BaseDataBindingActivity
import com.google.android.material.snackbar.Snackbar
import com.learn.databinding.R
import com.learn.databinding.databinding.ActivityLayoutAndBindingExpressionBinding
import com.learn.databinding.layoutandbindingexpression.model.UserModel

class LayoutAndBindingExpressionActivity :
    BaseDataBindingActivity<ActivityLayoutAndBindingExpressionBinding>() {
    override val layoutResId: Int
        get() = R.layout.activity_layout_and_binding_expression


    override fun setToolbar() {
        mToolbar.setTitle("LayoutAndBindingExpression")
    }

    override fun initView() {
        mDataBinding.user = UserModel("花", "木兰")
        mDataBinding.presenter = Presenter()
    }

    /**
     * 事件处理类
     */
    inner class Presenter {
        /**
         * 事件处理方法
         * 注意：这里的参数任意，但是该方法的返回值必须要调用的方法返回值相同
         */
        fun onClickFirstName(view: View, firstName: String) {
            Toast.makeText(view.context, "Click", Toast.LENGTH_SHORT).show()
            Log.d("onClickFirstName", firstName)
        }

        fun onCheckedChange(view: View, isChecked: Boolean, lastName: String) {
            Toast.makeText(view.context, "$lastName->$isChecked", Toast.LENGTH_SHORT).show()
        }

        fun onLongClick(view: View, lastName: String): Boolean {
            Toast.makeText(view.context, lastName, Toast.LENGTH_SHORT).show()
            return true
        }
        fun onClickWithContext(context: Context,view: View){
            Toast.makeText(context,"onClickWithContext",Toast.LENGTH_SHORT).show()
            Snackbar.make(view,"onClickWithContext",Snackbar.LENGTH_SHORT).show()
        }
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            Intent(context, LayoutAndBindingExpressionActivity::class.java)
                .also {
                    context.startActivity(it)
                }
        }
    }
}